package com.starbucks.opencase.tool;

import com.starbucks.opencase.entity.entGoodsInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class toolUserScan {
    @Autowired
    private JdbcTemplate con;

    /**
     * 随机抽取一个物品
     * @return
     */
    public entGoodsInfo randomGoods(){
        List<entGoodsInfo> as= con.query("select * from goods_info order by rand() limit 1", new BeanPropertyRowMapper<>(entGoodsInfo.class));
        if(as.isEmpty())return new entGoodsInfo();
        return as.get(0);
    }

}
